﻿using RXY_Mall.Application.Manager;
using RXY_Mall.Application.Shop;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace RXY_Mall.Shop.Controllers
{
    public class SettingController : BaseController
    {
        protected IManagerService _managerService;
        private IShopService _shopService;
        public SettingController()
        {
            _managerService = new ManagerService();
            _shopService = new ShopService();
        }
        public ActionResult Company()
        {
            var model = _shopService.GetCompanyByShopId(ShopId);
            return View(model);
        }
        [HttpGet]
        public JsonResult GetCompanyInfo()
        {
            var model = _shopService.GetCompanyByShopId(ShopId);
            return model == null ? null : Json(model, JsonRequestBehavior.AllowGet);
        }

        public ActionResult ShopInfo()
        {
            var model = _shopService.GetShopById(ShopId);
            return View(model);
        }
        [HttpGet]
        public JsonResult GetStoreInfo()
        {
            var model = _shopService.GetShopById(ShopId);
            return model==null?null:Json(model, JsonRequestBehavior.AllowGet);
        }

        public ActionResult UpdatePwd()
        {
            return View();
        }
        public ActionResult UpdatePayPwd()
        {
            return View();
        }
        [HttpPost]
        public ActionResult MotifyUserPwd(string oldPassword, string newPassword, string confirmPassword)
        {
            if (newPassword != confirmPassword)
            {
                return Json(new { status = "n", info = "新密码和确认密码不一致" });
            }
            var result = _managerService.UpdatePassword(MemberId, oldPassword, newPassword);
            if (result.code == 1)
            {
                return Json(new { status = "y", info = "修改成功。" });
            }
            else
            {
                return Json(new { status = "n", info = result.msg });
            }
        }

        [HttpPost]
        public ActionResult MotifyPayPwd(string oldPassword, string newPassword, string confirmPassword)
        {
            if (newPassword != confirmPassword)
            {
                return Json(new { status = "n", info = "新密码和确认密码不一致" });
            }
            var result = _managerService.UpdatePayPassword(MemberId, ShopId,oldPassword, newPassword);
            if (result.code == 1)
            {
                return Json(new { status = "y", info = "修改成功。" });
            }
            else
            {
                return Json(new { status = "n", info = "原密码错误。" });
            }
        }
    }
}